Skip to content

Compile the Gradle plugin as Java: convert its last Groovy class and leave src/main/groovy - #263

Merged
abashev merged 4 commits into
21.X.Xfrom
abashev/Migrate-from-groovy
Nov 23, 2026
Merged

abashev merged 4 commits into
21.X.Xfrom
abashev/Migrate-from-groovy

Conversation

@abashev

@abashev abashev commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Closes #261. Independent of the other open pull requests; based on 21.X.X.

Seven classes of the Gradle plugin lived in gradle-open-java-format/src/main/groovy because of ConfigureJavaFormatterXml.groovy, the only Groovy source in the repository: Java that calls a Groovy class compiles only jointly with it, and compileGroovy is no JavaCompile task, so Error Prone and NullAway skipped the six Java files among them. #261 has how it came to this.

Commits

  1. Convert ConfigureJavaFormatterXml to Java, in place and still on groovy.util.Node: the same conversion as Convert ConfigureJavaFormatterXml from Groovy to Java palantir/palantir-java-format#1855, a draft upstream, without its revapi part. A new child gets a LinkedHashMap of attributes, since a Node keeps the map it is created with and the class puts values in it afterwards, which Map.of would refuse. The class is package-private now.
  2. Move the seven files to src/main/java and drop apply plugin: 'groovy'. Renames only, so git log --follow goes on past them.
  3. ReferenceEquality, the one finding Error Prone has for the moved files: rootProject == rootProject.getRootProject() in PalantirJavaFormatIdeaPlugin. The two other root-project plugins had the same line, flagged already; all three compare with equals now, which Project does not override. NullAway finds nothing.
  4. StaticImport across the module, main and test sources: Preconditions.checkState and checkNotNull, Collectors, Collections.singletonList, Comparator.reverseOrder, Objects.requireNonNull and Pattern.MULTILINE.

What stays

  • What the plugins do and what they write into .idea. The XML is still read and written with Groovy's XmlParser and XmlNodePrinter, which come with gradleApi(); replacing them changes the text of the files and is Edit the .idea XML files with the JDK's DOM instead of Groovy's XmlParser #262.
  • No @SuppressWarnings("unchecked") in ConfigureJavaFormatterXml: Node.attributes() is a raw Map, and javac prints its "uses unchecked or unsafe operations" note for the file, as it does for files of open-java-format.
  • Error Prone's other warnings in the module, older than this change: ConstantNaming and InjectOnConstructorOfAbstractClass in SpotlessInterop, AnnotateFormatMethod in GradleTestProject.

Tests

./gradlew :gradle-open-java-format:check passes on JDK 21: 141 tests, checkstyle, forbidden-apis and validatePlugins. ConfigureJavaFormatterXmlTest and PalantirJavaFormatIdeaPluginTest pass on the first two commits on their own. The jar has the seven classes, and javadocJar and sourcesJar build. PalantirJavaFormatPluginTest, PalantirJavaFormatSpotlessPluginTest and FormatDiffTest need the native image and are left to CI's native jobs. The root build applies the published 21.0.2 plugin, so no other module builds with this one.

It was the only Groovy source in the repository, written when the IDEA
plugin edited the .ipr through idea.project.ipr.withXml, which hands
over a groovy.util.Node. The tasks have read and written the .idea
files themselves since palantir#1306, and the
class stays on groovy.util.Node, as XmlUtils does.

A Node keeps the map of attributes it is created with, and the class
puts values in it afterwards, so a new child gets a LinkedHashMap
rather than Map.of. The class is package-private: only the tasks next
to it and its test call it.

The same conversion as palantir#1855, still a
draft upstream. Part of #261.
compileJava runs before compileGroovy, so Java that calls a Groovy
class compiles only from the Groovy source directory: the tasks that
call ConfigureJavaFormatterXml, PalantirJavaFormatIdeaPlugin, which
registers them, and PalantirJavaFormatPlugin, which applies it, lived
there, and XmlUtils next to its callers. With the Groovy class gone
they move to src/main/java, and the groovy plugin goes.

compileGroovy is no JavaCompile task, so Error Prone and NullAway
skipped these files until now.

The groovy.xml classes stay: they come with gradleApi(), and replacing
them is #262. Part of #261.
Error Prone flags rootProject == rootProject.getRootProject() in
PalantirJavaFormatIdeaPlugin now that it compiles it, and it flagged
the same check in the two other root-project plugins already. Project
does not override equals, so the check does not change.
Picnic's StaticImport suggested it for Preconditions.checkState and
checkNotNull, Collectors, Collections.singletonList,
Comparator.reverseOrder, Objects.requireNonNull and Pattern.MULTILINE,
in the main and test sources of gradle-open-java-format. The module
compiles without a StaticImport note now.
@abashev
abashev merged commit a839465 into 21.X.X Nov 23, 2026
16 checks passed
@abashev
abashev deleted the abashev/Migrate-from-groovy branch November 23, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move the Gradle plugin's sources out of src/main/groovy, so that Error Prone checks them

1 participant